#include "connection.hpp"


// int main()
// {
//     //实例化异步工作线程对象
//     MyRabbitMQ::AsyncWorker::ptr aw = std::make_shared<MyRabbitMQ::AsyncWorker>();
    
//     //实例化连接对象
//     MyRabbitMQ::Connection::ptr connect = std::make_shared<MyRabbitMQ::Connection>("127.0.0.1",8085,aw);
    
//     //通过连接对象实例化信道对象
//     MyRabbitMQ::Channel::ptr channel = connect->createChannel();

//     google::protobuf::Map<std::string, std::string> args;
    
//     //声明交换机
//     channel->declareExchange("exchange-1",protoMQ::ExchangeType::fanout,false,false,args);

//     //声明队列
//     channel->declareQueue("queue-1",false,false,false,args);
//    // channel->declareQueue("queue-2",false,false,false,args);

//     //绑定
//     channel->bind("exchange-1","queue-1","rivellon");
//    // channel->bind("exchange-1","queue-2","hello");

//     //测试发布客户端
//     for(int i = 0; i < 10; i++)
//     {
//         channel->basicPublish("exchange-1",nullptr,"hello-" + std::to_string(i));
//     }

//     while(1) 
//     {
//         std::this_thread::sleep_for(std::chrono::seconds(3));
//     }

//     connect->deleteChannel(channel->getChannelId());

//     connect.reset();

//     return 0;
// }

int main()
{
    //实例化异步工作线程对象
    MyRabbitMQ::AsyncWorker::ptr aw = std::make_shared<MyRabbitMQ::AsyncWorker>();
    
    //实例化连接对象
    MyRabbitMQ::Connection::ptr connect = std::make_shared<MyRabbitMQ::Connection>("127.0.0.1",8085,aw);
    
    //通过连接对象实例化信道对象
    MyRabbitMQ::Channel::ptr channel = connect->createChannel();

    google::protobuf::Map<std::string, std::string> args;
    
    //声明交换机
    channel->declareExchange("exchange-1",protoMQ::ExchangeType::fanout,false,false,args);

    //测试发布客户端
    for(int i = 0; i < 10; i++)
    {
        sleep(3);
        LOG(logLevel::TEST) << "休眠3秒" << std::endl;
        channel->basicPublish("exchange-1",nullptr,"hello-" + std::to_string(i));
    }

    while(1) 
    {
        std::this_thread::sleep_for(std::chrono::seconds(3));
    }

    connect->deleteChannel(channel->getChannelId());

    connect.reset();

    return 0;
}